package com.hzdesk.media.koreabatchmatvector.logic.view;

import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.adapter.ColorPickerAdapter;
import com.hzdesk.media.koreabatchmatvector.config.AppConfig;
import com.hzdesk.media.koreabatchmatvector.logic.contract.ChangeMouseSetCotract;
import com.hzdesk.media.koreabatchmatvector.logic.persenter.ChangeMouseSetPersenter;
import com.hzdesk.media.koreabatchmatvector.utils.MyToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/7/17.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class ChangeMouseSetActivity extends BaseActivity implements ChangeMouseSetCotract.IChangeMouseSetView {

    @BindView(R.id.activity_change_mouse_set_iv_return)
    ImageView activityChangeMouseSetIvReturn;
    @BindView(R.id.activity_change_mouse_set_et_input_name)
    EditText activityChangeMouseSetEtInputName;
    @BindView(R.id.activity_change_mouse_set_rl_input_name)
    RelativeLayout activityChangeMouseSetRlInputName;
    @BindView(R.id.activity_change_mouse_set_iv_return_01)
    ImageView activityChangeMouseSetIvReturn01;
    @BindView(R.id.activity_change_mouse_set_rl_cursor_color)
    RelativeLayout activityChangeMouseSetRlCursorColor;
    @BindView(R.id.activity_change_mouse_set_iv_return_02)
    ImageView activityChangeMouseSetIvReturn02;
    @BindView(R.id.activity_change_mouse_set_rl_path_size)
    RelativeLayout activityChangeMouseSetRlPathSize;
    @BindView(R.id.activity_change_mouse_set_iv_return_03)
    ImageView activityChangeMouseSetIvReturn03;
    @BindView(R.id.activity_change_mouse_set_rl_disable)
    RelativeLayout activityChangeMouseSetRlDisable;
    @BindView(R.id.activity_change_mouse_set_rl_save_setting)
    RelativeLayout activityChangeMouseSetRlSaveSetting;
    @BindView(R.id.activity_change_mouse_set_ll_skin_01)
    LinearLayout activityChangeMouseSetLlSkin01;
    @BindView(R.id.activity_change_mouse_set_tv_color)
    TextView activityChangeMouseSetTvColor;
    @BindView(R.id.activity_change_mouse_set_tv_path_size)
    TextView activityChangeMouseSetTvPathSize;
    @BindView(R.id.activity_change_mouse_set_tv_disable)
    TextView activityChangeMouseSetTvDisable;
    @BindView(R.id.activity_change_mouse_set_tv_title)
    TextView activityChangeMouseSetTvTitle;
    @BindView(R.id.activity_change_mouse_set_iv_return_paint)
    ImageView activityChangeMouseSetIvReturnPaint;
    @BindView(R.id.activity_change_mouse_set_tv_patin_color)
    TextView activityChangeMouseSetTvPatinColor;
    @BindView(R.id.activity_change_mouse_set_rl_paint_color)
    RelativeLayout activityChangeMouseSetRlPaintColor;
    private int item_postion;
    private ChangeMouseSetPersenter mChangeMouseSetPersenter = new ChangeMouseSetPersenter(this);
    private int REQUEST_GET_PATH = 0;
    private int REQUEST_GET_Color = 1;
    private int REQUEST_GET_PAINT_COLOR=2;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_mouse_set);
        ButterKnife.bind(this);

        mChangeMouseSetPersenter.initListenting(activityChangeMouseSetRlInputName);
        mChangeMouseSetPersenter.initListenting(activityChangeMouseSetRlCursorColor);
        mChangeMouseSetPersenter.initListenting(activityChangeMouseSetRlPathSize);
        mChangeMouseSetPersenter.initSaveDate(activityChangeMouseSetRlSaveSetting);
        //mChangeMouseSetPersenter.initListenting(activityChangeMouseSetRlSaveSetting);
        mChangeMouseSetPersenter.initListenting(activityChangeMouseSetRlDisable);
        mChangeMouseSetPersenter.initListenting(activityChangeMouseSetRlPaintColor);
        item_postion = getIntent().getIntExtra("item_postion", 0);
        mChangeMouseSetPersenter.initSettingDate(item_postion, this);
    }

    @OnClick({R.id.activity_change_mouse_set_iv_return, R.id.activity_change_mouse_set_rl_cursor_color,
            R.id.activity_change_mouse_set_rl_path_size, R.id.activity_change_mouse_set_rl_disable,
            R.id.activity_change_mouse_set_rl_save_setting,R.id.activity_change_mouse_set_rl_paint_color})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_change_mouse_set_iv_return:
                mChangeMouseSetPersenter.onclickedBack();
                break;
            case R.id.activity_change_mouse_set_rl_cursor_color:
                mChangeMouseSetPersenter.onClickedCursorColor();
                break;
            case R.id.activity_change_mouse_set_rl_path_size:
                mChangeMouseSetPersenter.onClickedPathSize();
                break;
            case R.id.activity_change_mouse_set_rl_disable:
                mChangeMouseSetPersenter.onClickedDisable(this);
                break;
            case R.id.activity_change_mouse_set_rl_save_setting:
                mChangeMouseSetPersenter.onClickedSaveSetting(this);
                break;
            case R.id.activity_change_mouse_set_rl_paint_color:
                mChangeMouseSetPersenter.onClickedPaintColor();
                break;
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        final SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        int selector = mSharedPreferences.getInt("item_skin", 0); //todo 名称
        activityChangeMouseSetLlSkin01.setBackgroundResource(updateBg[selector]);


    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        item_postion = intent.getIntExtra("item_postion", 0);
        mChangeMouseSetPersenter.initSettingDate(item_postion, this);

        // Log.e("ChangeMouseSetPersenter", "onNewIntent:====================> ");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // todo 显示设置的光标颜色和笔触大小
        mChangeMouseSetPersenter.showCursorAndPathSize(this);
        mChangeMouseSetPersenter.onActivityResult(requestCode,resultCode,data);
        // Log.e("ChangeMouseSetPersenter", "onNewIntent:====================> ");



    }

    @Override
    public void finshPager() {
        finish();
    }

    @Override
    public String getInputName() {
        return activityChangeMouseSetEtInputName.getText().toString().trim();
    }

    @Override
    public String getCursorColor() {
        return activityChangeMouseSetTvColor.getText().toString().trim();
    }

    @Override
    public String getPathSize() {
        return activityChangeMouseSetTvPathSize.getText().toString().trim();
    }

    @Override
    public String getDisable() {
        return activityChangeMouseSetTvDisable.getText().toString().trim();
    }

    @Override
    public void setInputName(String color) {
        activityChangeMouseSetTvColor.setText(color);
    }

    @Override
    public void setPathSize(String size) {
        activityChangeMouseSetTvPathSize.setText(size);
    }

    @Override
    public void setDisable(String disable) {
        activityChangeMouseSetTvDisable.setText(disable);
    }

    @Override
    public void toCursorColorSelectorPager() {
        Intent intent = new Intent();
        intent.setClass(ChangeMouseSetActivity.this, OptionActivity.class);
        intent.putExtra("Option", AppConfig.OPTION_CURSOR_COLOR);
        startActivityForResult(intent, REQUEST_GET_Color);
    }

    @Override
    public void toPathSizeSelectorPager() {
        Intent intent = new Intent();
        intent.setClass(ChangeMouseSetActivity.this, OptionActivity.class);
        intent.putExtra("Option", AppConfig.OPTION_path_size);
        startActivityForResult(intent, REQUEST_GET_PATH);
    }
    @Override
    public void toColorPickerPager() {
        Intent intent=new Intent();
        intent.setClass(ChangeMouseSetActivity.this, ColorpickerActivity.class);
        startActivityForResult(intent,REQUEST_GET_PAINT_COLOR);
    }

    @Override
    public void changePaintColor(String color) {
        activityChangeMouseSetTvPatinColor.setTextColor(Color.parseColor("#" + color));
    }

    @Override
    public void SetTile(String title) {
        activityChangeMouseSetTvTitle.setText(title);
    }

    @Override
    public void setName(String myName) {
        activityChangeMouseSetEtInputName.setText(myName);
    }

    @Override
    public void showToast(String msg) {
        MyToastUtils.ShortToaseShow(this, msg);
    }

    @Override
    public void showColorAndSize(String color, String size) {
        activityChangeMouseSetTvColor.setText(color);
        activityChangeMouseSetTvPathSize.setText(size);
    }




}
